Imports PTT.CarRes.Data

Public Class ClassQueryInvApproveTime
    Public Function Add(ByVal InvApproveTime As QueryInvApproveTime, ByVal Strconn As String) As Boolean
        Dim ClsInvApproveTime As New ClassInvApproveTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvApproveTime.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvApproveTime
            .TimeId = InvApproveTime.TimeId
            .ApproveTime = InvApproveTime.ApproveTime
            ret = .USP_Save(Conn)
        End With
        ClsInvApproveTime.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvApproveTime As QueryInvApproveTime, ByVal Strconn As String) As Boolean
        Dim ClsInvApproveTime As New ClassInvApproveTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvApproveTime.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvApproveTime
            .TimeId = InvApproveTime.TimeId
            .Load(Conn)
            .ApproveTime = InvApproveTime.ApproveTime
            ret = .USP_Update(Conn)
        End With
        ClsInvApproveTime.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvApproveTime As QueryInvApproveTime, ByVal Strconn As String) As Boolean
        Dim ClsInvApproveTime As New ClassInvApproveTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvApproveTime.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvApproveTime
            .TimeId = InvApproveTime.TimeId
            .Load(Conn)
            .ApproveTime = InvApproveTime.ApproveTime
            ret = .USP_Delete(Conn)
        End With
        ClsInvApproveTime.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaTimeId As String = "", _
    Optional ByVal ParaApproveTime As String = "", Optional ByVal Strconn As String = "") As QueryInvApproveTimes
        Dim ClsInvApproveTime As New ClassInvApproveTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvApproveTime.ConnectionOpen(Strconn)
        Dim ret As QueryInvApproveTimes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvApproveTime"
        If ParaTimeId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(TimeId = " & ParaTimeId & ")"
        End If
        If ParaApproveTime & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(ApproveTime like '%" & ParaApproveTime & "%')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvApproveTime
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvApproveTimes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvApproveTime( _
                              .Item("TimeId") & "", _
                              .Item("ApproveTime") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvApproveTime.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaTimeId As String = "", Optional ByVal Strconn As String = "") As QueryInvApproveTimes
        Dim ClsInvApproveTime As New ClassInvApproveTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvApproveTime.ConnectionOpen(Strconn)
        Dim ret As QueryInvApproveTimes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvApproveTime"
        If ParaTimeId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(TimeId = " & ParaTimeId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvApproveTime
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvApproveTimes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvApproveTime( _
                              .Item("TimeId") & "", _
                              .Item("ApproveTime") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvApproveTime.ConnectionClose(Conn)
        Return ret
    End Function
End Class
